import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNot.not;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
import java.util.*;
import java.net.MalformedURLException;
import java.net.URL;
public class PSYInformationAdminTest {
  private WebDriver driver;
  private Map<String, Object> vars;
  JavascriptExecutor js;
  @Before
  public void setUp() {
    driver = new ChromeDriver();
    js = (JavascriptExecutor) driver;
    vars = new HashMap<String, Object>();
  }
  @After
  public void tearDown() {
    driver.quit();
  }
  public void PSYLoginAdminTrue01() {
    driver.get("https://sei-test.021hqit.com/group-5/group-5/");
    driver.findElement(By.cssSelector(".el-form-item:nth-child(1) .el-input__inner")).sendKeys("ecnu_admin");
    driver.findElement(By.cssSelector(".el-form-item:nth-child(2) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-form-item:nth-child(2) .el-input__inner")).sendKeys("pl,okm123");
    driver.findElement(By.cssSelector(".el-button")).click();
    vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
    assertEquals(vars.get("message").toString(), "登录成功");
  }
  public void PSYInformationAdminRollback() {
    if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'avatar\').length > 0)")) {
      {
        WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
        Actions builder = new Actions(driver);
        builder.moveToElement(element).perform();
      }
      driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
      driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
      driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
      driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
      driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
      driver.findElement(By.cssSelector(".confirm")).click();
      vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
      assertEquals(vars.get("message").toString(), "修改成功");
    }
  }
  @Test
  public void pSYInformationAdminTrue01() {
    PSYLoginAdminTrue01();
    vars.put("originPassword", "pl,okm123");
    vars.put("newPassword", "123321");
    {
      WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".confirm")).click();
    vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    assertEquals(vars.get("message").toString(), "修改成功");
    PSYInformationAdminRollback();
  }
  @Test
  public void pSYInformationAdminFalse016() {
    PSYLoginAdminTrue01();
    vars.put("originPassword", "pl,okm123");
    vars.put("newPassword", "123");
    {
      WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".confirm")).click();
    if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'message\').length > 0)")) {
      vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
      assertEquals(vars.get("message").toString(), "修改失败");
      PSYInformationAdminRollback();
    } else {
      vars.put("message", driver.findElement(By.cssSelector(".el-form-item__error")).getText());
      assertEquals(vars.get("message").toString(), "密码只能由长度为6-20的数字、字母、下划线组成");
    }
  }
  @Test
  public void pSYInformationAdminFalse026() {
    PSYLoginAdminTrue01();
    vars.put("originPassword", "pl,okm123");
    vars.put("newPassword", "123ab");
    {
      WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".confirm")).click();
    if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'message\').length > 0)")) {
      vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
      assertEquals(vars.get("message").toString(), "修改失败");
      PSYInformationAdminRollback();
    } else {
      vars.put("message", driver.findElement(By.cssSelector(".el-form-item__error")).getText());
      assertEquals(vars.get("message").toString(), "密码只能由长度为6-20的数字、字母、下划线组成");
    }
  }
  @Test
  public void pSYInformationAdminFalse03() {
    PSYLoginAdminTrue01();
    vars.put("originPassword", "pl,okm123");
    vars.put("newPassword", ",,,,,,");
    {
      WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".confirm")).click();
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'el-message\').length > 0)")) {
      vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
      assertEquals(vars.get("message").toString(), "修改失败");
      PSYInformationAdminRollback();
    } else {
      vars.put("message", driver.findElement(By.cssSelector(".el-form-item__error")).getText());
      assertEquals(vars.get("message").toString(), "密码只能由长度为6-20的数字、字母、下划线组成");
    }
  }
  @Test
  public void pSYInformationAdminFalse04() {
    PSYLoginAdminTrue01();
    vars.put("originPassword", "pl,okm123");
    vars.put("newPassword", ",+=-1a");
    {
      WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".confirm")).click();
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'el-message\').length > 0)")) {
      vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
      assertEquals(vars.get("message").toString(), "修改失败");
      PSYInformationAdminRollback();
    } else {
      vars.put("message", driver.findElement(By.cssSelector(".el-form-item__error")).getText());
      assertEquals(vars.get("message").toString(), "密码只能由长度为6-20的数字、字母、下划线组成");
    }
  }
  @Test
  public void pSYInformationAdminFalse0520() {
    PSYLoginAdminTrue01();
    vars.put("originPassword", "pl,okm123");
    vars.put("newPassword", "aaaaaaaaaa11111111112");
    {
      WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".confirm")).click();
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'el-message\').length > 0)")) {
      vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
      assertEquals(vars.get("message").toString(), "修改失败");
      PSYInformationAdminRollback();
    } else {
      vars.put("message", driver.findElement(By.cssSelector(".el-form-item__error")).getText());
      assertEquals(vars.get("message").toString(), "密码只能由长度为6-20的数字、字母、下划线组成");
    }
  }
  @Test
  public void pSYInformationAdminFalse0620() {
    PSYLoginAdminTrue01();
    vars.put("originPassword", "pl,okm123");
    vars.put("newPassword", "123456789,qwertyuiosdgshja");
    {
      WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".confirm")).click();
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'el-message\').length > 0)")) {
      vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
      assertEquals(vars.get("message").toString(), "修改失败");
      PSYInformationAdminRollback();
    } else {
      vars.put("message", driver.findElement(By.cssSelector(".el-form-item__error")).getText());
      assertEquals(vars.get("message").toString(), "密码只能由长度为6-20的数字、字母、下划线组成");
    }
  }
  @Test
  public void pSYInformationAdminFalse07() {
    PSYLoginAdminTrue01();
    vars.put("originPassword", "pl,okm123");
    vars.put("newPassword", "123456789");
    {
      WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".confirm")).click();
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'el-message\').length > 0)")) {
      vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
      assertEquals(vars.get("message").toString(), "修改失败");
      PSYInformationAdminRollback();
    } else {
      vars.put("message", driver.findElement(By.cssSelector(".el-form-item__error")).getText());
      assertEquals(vars.get("message").toString(), "请输入原密码");
    }
  }
  @Test
  public void pSYInformationAdminFalse08() {
    PSYLoginAdminTrue01();
    vars.put("originPassword", "pl,okm123");
    vars.put("newPassword", "123456789");
    {
      WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("originPassword").toString()1);
    driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".confirm")).click();
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'el-message\').length > 0)")) {
      vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
      assertEquals(vars.get("message").toString(), "原密码错误");
      if ((Boolean) js.executeScript("return (arguments[0]==\'修改成功·\')", vars.get("message"))) {
        PSYInformationAdminRollback();
      }
    } else if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'el-form-item__error\').length > 0)")) {
      vars.put("message", driver.findElement(By.cssSelector(".el-form-item__error")).getText());
      assertEquals(vars.get("message").toString(), "请输入原密码");
    }
  }
  @Test
  public void pSYInformationAdminFalse09() {
    PSYLoginAdminTrue01();
    vars.put("originPassword", "pl,okm123");
    vars.put("newPassword", "123456789");
    {
      WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".confirm")).click();
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'el-message\').length > 0)")) {
      vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
      assertEquals(vars.get("message").toString(), "修改失败");
      PSYInformationAdminRollback();
    } else {
      vars.put("message", driver.findElement(By.cssSelector(".el-form-item__error")).getText());
      assertEquals(vars.get("message").toString(), "请再次输入密码");
    }
  }
  @Test
  public void pSYInformationAdminFalse10() {
    PSYLoginAdminTrue01();
    vars.put("originPassword", "pl,okm123");
    vars.put("newPassword", "123456789");
    {
      WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("newPassword").toString()1);
    driver.findElement(By.cssSelector(".confirm")).click();
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'el-message\').length > 0)")) {
      vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
      assertEquals(vars.get("message").toString(), "修改失败");
      PSYInformationAdminRollback();
    } else {
      vars.put("message", driver.findElement(By.cssSelector(".el-form-item__error")).getText());
      assertEquals(vars.get("message").toString(), "两次输入密码不一致!");
    }
  }
  @Test
  public void pSYInformationAdminRollback() {
    if ((Boolean) js.executeScript("return (document.getElementsByClassName(\'avatar\').length > 0)")) {
      {
        WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
        Actions builder = new Actions(driver);
        builder.moveToElement(element).perform();
      }
      driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
      driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
      driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
      driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
      driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
      driver.findElement(By.cssSelector(".confirm")).click();
      vars.put("message", driver.findElement(By.cssSelector(".el-message")).getText());
      assertEquals(vars.get("message").toString(), "修改成功");
    }
  }
  @Test
  public void pSYInformationAdminCancel01() {
    PSYLoginAdminTrue01();
    vars.put("originPassword", "pl,okm123");
    vars.put("newPassword", "123321");
    {
      WebElement element = driver.findElement(By.cssSelector(".avatar > img"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(1)")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).click();
    driver.findElement(By.cssSelector(".el-row:nth-child(1) .el-input__inner")).sendKeys(vars.get("originPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(2) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".el-row:nth-child(3) .el-input__inner")).sendKeys(vars.get("newPassword").toString());
    driver.findElement(By.cssSelector(".cancel")).click();
  }
}
